<?php

require_once dirname(__FILE__) . '/../lib/reclamoGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/reclamoGeneratorHelper.class.php';

/**
 * reclamo actions.
 *
 * @package    reclamos
 * @subpackage reclamo
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class reclamoActions extends autoReclamoActions
{

  public function executeNew(sfWebRequest $request)
  {
    $reclamo = new Reclamo();
    $reclamo->setSfGuardUserId($this->getUser()->getGuardUser()->getId());

    $this->form = new ReclamoLegajoAUForm($reclamo);
    $this->reclamo = $this->form->getObject();

  }

  public function buildCriteria()
  {
    $asuntos_ids = ReclamoPeer::getAsuntosQuePuedenGenerarLegajosAu();

    $c = parent::buildCriteria();
    $c->add(ReclamoPeer::ESTADO, Estado0800::ESTADO0800_PENDIENTE, Criteria::EQUAL);

    $c->addOr(ReclamoPeer::ESTADO, null, Criteria::ISNULL);
    $c->add(ReclamoPeer::ASUNTO_ID, $asuntos_ids, Criteria::IN);
    $c->addOr(ReclamoPeer::ASUNTO_ID, null, Criteria::ISNULL);
    $c->addDescendingOrderByColumn(ReclamoPeer::LEGAJO_CAU);
    return $c;

  }

  public function executeVerDictamenes(sfWebRequest $request)
  {
    $this->forward('dictamen', 'index');

  }

  public function executeAgregarDictamen(sfWebRequest $request)
  {
    $this->forward('dictamen', 'new');

  }

  public function executeArchivar(sfWebRequest $request)
  {
    $reclamo = ReclamoPeer::retrieveByPK($request->getParameter('id'));
    $reclamo->setArchivado(true);
    $reclamo->save();
    $this->redirect('reclamo');

  }

  public function executeDesarchivar(sfWebRequest $request)
  {
    $reclamo = ReclamoPeer::retrieveByPK($request->getParameter('id'));
    $reclamo->setArchivado(false);
    $reclamo->save();
    $this->redirect('reclamo');

  }

  public function executeGenerarLegajoAu(sfWebRequest $request)
  {
    $reclamo = ReclamoPeer::retrieveByPK($request->getParameter('id'));
    $reclamo->generarLegajoAu();
    $reclamo->save();
    $this->redirect('reclamo');

  }

  public function executeImprimirReclamo()
  {
    $this->setLayout('cleanLayout');
    $this->back = '@reclamo';
    $this->reclamo = $this->getRoute()->getObject();

  }

  public function executeIndexByCliente(sfWebRequest $request)
  {
    parent::executeIndex($request);
    #ver esto para generar boton de volver
    #$this->getUser()->setAttribute('action', 'indexByPersona');
    $c = new Criteria();
    $c->add(ReclamoPeer::CLIENTE_ID, $this->getUser()->getAttribute('cliente_id'));
    $this->pager->setCriteria($c);
    $this->pager->init();
    $this->setTemplate('index');

  }

  public function executeImprimirCaractula(sfWebRequest $request)
  {
    $this->setLayout('cleanLayout');
    $this->back = '@reclamo';
    $this->Reclamo = $this->getRoute()->getObject();
    $this->reclamo = $this->getRoute()->getObject();
    $this->form = $this->configuration->getForm($this->reclamo);

  }

}
